#include "TreeItem_SubBook.h"
#include "TreeItem_Book.h"
#include "TreeItem_Chapter.h"
#include "DataBaseManager.h"
#include "Common.h"

#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlRecord>
#include <QtSql/QSqlError>
#include <QtCore/QVariant>
#include <QtCore/QDebug>

namespace Jonathan
{

   /**
    * @brief Initializes a new sub book tree item.
    *
    * @param parent Parent tree item.
    */
   TreeItem_SubBook::TreeItem_SubBook (QString bookName, int chapterCount, QTreeWidgetItem *parent) :
      IBookListItem (parent), m_Name(bookName), m_NumChapters (chapterCount)
   {
      this->setText (0, this->m_Name);
      this->setIcon (0, Common::GetIcon (ICON_SubBook));
      this->addChild (new QTreeWidgetItem ());
   }

   /**
    * @brief Loads any children items for the book.
    *
    */
   void TreeItem_SubBook::LoadChildren ()
   {
      for (int a = 1; a <= this->m_NumChapters; a++)
         this->addChild (new TreeItem_Chapter (a, this));
   }

   /**
    * @brief Gets the name of the book.
    *
    * @return QString Name of the book.
    */
   QString TreeItem_SubBook::GetName ()
   {
      return this->m_Name;
   }

}
